package com.pzh.guli.service.edu.controller.api;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.pzh.guli.service.base.dto.CourseDto;
import com.pzh.guli.service.base.result.Result;
import com.pzh.guli.service.edu.mapper.CourseMapper;
import com.pzh.guli.service.edu.pojo.Course;

import com.pzh.guli.service.edu.pojo.vo.WebCourseQuery;
import com.pzh.guli.service.edu.pojo.vo.WebCourseVo;
import com.pzh.guli.service.edu.service.ICourseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/api/edu/course")
public class ApiCourseController {
    @Resource
   private CourseMapper courseMapper;
    @Autowired
    private ICourseService courseService;
    //根据教师id查所属课程
    @GetMapping("course-info/{id}")
    public Result getCourseByTeacherId(@PathVariable String id){
        QueryWrapper<Course> courseQueryWrapper=new QueryWrapper<>();
        courseQueryWrapper.eq("teacher_id",id);
        List<Course> courses = courseMapper.selectList(courseQueryWrapper);
        return Result.ok().data("items",courses);
    }
    //查询所有课程
    @PostMapping("course-info")
    public Result getAllCourse(@RequestBody WebCourseQuery webCourseQuery){
        List<Course> courseList = courseService.getCourseByQuery(webCourseQuery);
        return Result.ok().data("items",courseList);
    }
    // 课程播放详细信息
    @GetMapping("coursePay/{id}")
    public Result getCoursePayInfo(@PathVariable String id){
        WebCourseVo webCourseVo=courseService.getCoursePay(id);
        return Result.ok().data("item",webCourseVo);
    }
    //前台热门课程
    @GetMapping("topCourse")
    public Result getTopCourse(){
        List<Course> topCourse = courseService.getTopCourse();
        return Result.ok().data("items",topCourse);
    }
    //订单查询课程模块
    @GetMapping("inner/get-course-dto/{courseId}")
    public CourseDto getCourseDto(@PathVariable String courseId){
        CourseDto courseDto=courseService.geCourseDtoById(courseId);
        return courseDto;
    }
}
